﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.ComponentModel;

namespace Jc.MicroDesigner.ToolWindows
{
    /// <summary>
    /// Конвертер для булевых свойств
    /// </summary>
    public class BooleanTypeConverter : BooleanConverter
    {
        /// <summary>
        /// Конвертировать
        /// </summary>
        /// <param name="context">Контекст</param>
        /// <param name="culture">Локаль</param>
        /// <param name="value">Значение</param>
        /// <param name="destType">Тип</param>
        /// <returns>Значение</returns>
        public override object ConvertTo(ITypeDescriptorContext context,
          CultureInfo culture,
          object value,
          Type destType)
        {
            return (bool)value ?
              "Да" : "Нет";
        }

        /// <summary>
        /// Конвертировать из
        /// </summary>
        /// <param name="context">Контекст</param>
        /// <param name="culture">Локаль</param>
        /// <param name="value">Значение</param>
        /// <returns>Значение</returns>
        public override object ConvertFrom(ITypeDescriptorContext context,
          CultureInfo culture,
          object value)
        {
            return (string)value == "Да";
        }
    }
}